package GameEngine.Gui;

import java.util.ArrayList;

import processing.core.PGraphics;
import processing.core.PImage;
import GameEngine.helper.PAppletBridge;

public class Menu extends GuiElement {
	private PImage Background = null;
	private ArrayList<GuiElement> Elements = new ArrayList<GuiElement>();

	public Menu(PImage img, int x, int y, int w, int h) {
		super(x, y, w, h);
		Background = img;
	}

	public void add(GuiElement g) {
		Elements.add(g);
	}
	
	public void drawAt(int x, int y) {
		PAppletBridge.pushMatrix();
		PAppletBridge.translate(x, y);
		draw();		
		PAppletBridge.popMatrix();
	}
	
	public void setActive(boolean active) {
		super.setActive(active);
		for (GuiElement ge : Elements) {
			ge.setActive(active);
		}		
	}

	@Override
	public void draw() {
		PAppletBridge.pushMatrix();

		PAppletBridge.imageMode(PAppletBridge.CORNERS);
		PAppletBridge.translate(PosX, PosY);
		
		// Zeichnen und speichern der Screen-Koordinaten
		PAppletBridge.image(Background, 0, 0);
		updateScreenXY(0,0);
		
		for (GuiElement ge : Elements) {
			ge.draw();
		}
		
		PAppletBridge.popMatrix();
	}



	@Override
	public PImage toImage() {
		PGraphics pg = PAppletBridge.createGraphics(Background.width,
				Background.height);
		pg.beginDraw();
		pg.pushMatrix();

		pg.translate(PosX, PosY);
		pg.image(Background, 0, 0);
		
		for (GuiElement ge : Elements) {
			ge.draw(pg);
		}

		pg.popMatrix();

		pg.endDraw();

		return pg;
	}

	@Override
	public void mouseOver(int x, int y) {
		// TODO Auto-generated method stub
	}

	@Override
	public void draw(PGraphics pg) {
		// TODO Auto-generated method stub
		
	}

}
